using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Reflection;
using System.Xml;
using System.Web;
using System.Web.UI;
using DotNetNuke;
using DotNetNuke.Common;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Services.Localization;
using DotNetNuke.Services.Search;

namespace Jfc.DnnMarketingTools.MemberInvite
{
    /// -----------------------------------------------------------------------------
    ///<summary>
    /// The Controller class for the MemberInviteSettings
    /// </summary>
    /// <remarks>
    /// </remarks>
    /// <history>
    /// </history>
    /// -----------------------------------------------------------------------------
    public class MemberInviteSettingsController
    {
        const string SettingsResourceFile = "~/DesktopModules/MemberInvite/App_LocalResources/UserSettings.ascx";

    #region Constructors

        public MemberInviteSettingsController()
        {
        }

    #endregion

    #region Public Methods

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// gets an object from the database
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="PortalId">The Id of the portal</param>
        /// <param name="UserId">The Id of the user</param>
        /// <history>
        /// </history>
        /// -----------------------------------------------------------------------------
        public MemberInviteSettingsInfo GetMemberInviteSettings(int PortalId, int UserId)
        {
            MemberInviteSettingsInfo memberInviteSettingsInfo;

            memberInviteSettingsInfo = CBO.FillObject<MemberInviteSettingsInfo>(DataProvider.Instance().GetMemberInviteSettings(PortalId, UserId));

            if (memberInviteSettingsInfo == null)
            {
                memberInviteSettingsInfo = new MemberInviteSettingsInfo();

                memberInviteSettingsInfo.PortalId = PortalId;
                memberInviteSettingsInfo.UserId = UserId;

                memberInviteSettingsInfo.SubjectTemplate = Localization.GetString("Default_SubjectTemplate.Text", SettingsResourceFile);
                memberInviteSettingsInfo.BodyTemplate = Localization.GetString("Default_BodyTemplate.Text", SettingsResourceFile);
            }

            return memberInviteSettingsInfo;
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// saves an object to the database
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="objMemberInvite">The MemberInviteInfo object</param>
        /// <history>
        /// </history>
        /// -----------------------------------------------------------------------------
        public void SetMemberInviteSettings(MemberInviteSettingsInfo objMemberInviteSettings)
        {
            if (!String.IsNullOrEmpty(objMemberInviteSettings.SubjectTemplate) &&
                !String.IsNullOrEmpty(objMemberInviteSettings.BodyTemplate))
            {
                DataProvider.Instance().SetMemberInviteSettings(objMemberInviteSettings.PortalId, objMemberInviteSettings.UserId, objMemberInviteSettings.SubjectTemplate, objMemberInviteSettings.BodyTemplate);
            }
        }

    #endregion
    }
}

